#include <iostream>
#include <cstring>
#include <set>
#include <string>
using namespace std;
const int MAXN = 6;
int dash[MAXN][MAXN];
int dxdy[][4] = {
    {0, 0, 1, -1},
    {1, -1, 0, 0}
};
bool check(int x, int y) {
    return x >= 0 && y >= 0 && x < 5 && y < 5;
}
void solve();
void dfs(int, int, int, int);
set<int> sets;
int main() {
    for (int i = 0; i < 5; i++)
        for (int j = 0; j < 5; j++)
            cin >> dash[i][j];
    solve();
}




void dfs(int x, int y, int step, int value) {
    if (step == 6) {
        if (sets.count(value) == 0) sets.insert(value);
        return;
    }
    for (int i = 0; i < 4; i++) {
        int nx = x + dxdy[0][i];
        int ny = y + dxdy[1][i];
        if (check(nx, ny))
            dfs(nx, ny, step + 1, value * 10 + dash[nx][ny]);
    }
}


void solve() {
    for (int i = 0; i < 5; i++) {
        for (int j = 0; j < 5; j++) {
            dfs(i, j, 1, dash[i][j]);
        }
    }
    cout << sets.size() << endl;
}